---
title: "Thesis Code Run in R"
author: "Anya Sorensen"
date: "4/28/2022"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(readxl)
FinalThesisAttacks <- read_excel("~/OneDrive - Dartmouth College/FinalThesisAttacks.xlsx")
```

This document runs through all of the code implemented to analyze my data. 


Number of Islamic State Terrorist attacks 
```{r}
table(FinalThesisAttacks$IS)
```

Attacks throughout the years
```{r}
table(FinalThesisAttacks$IS[FinalThesisAttacks$year==2016])
table(FinalThesisAttacks$IS[FinalThesisAttacks$year==2017])
table(FinalThesisAttacks$IS[FinalThesisAttacks$year==2018])
table(FinalThesisAttacks$IS[FinalThesisAttacks$year==2019])
table(FinalThesisAttacks$IS[FinalThesisAttacks$year==2020])
```

Target Type
```{r}
##Civilian
t.test(FinalThesisAttacks$Civilian[FinalThesisAttacks$IS==1], FinalThesisAttacks$Civilian[FinalThesisAttacks$IS==0])

##Religious
t.test(FinalThesisAttacks$Religious[FinalThesisAttacks$IS==1], FinalThesisAttacks$Religious[FinalThesisAttacks$IS==0])

##Police
t.test(FinalThesisAttacks$Police[FinalThesisAttacks$IS==1], FinalThesisAttacks$Police[FinalThesisAttacks$IS==0])

##Government/Infrastructure
t.test(FinalThesisAttacks$Government[FinalThesisAttacks$IS==1], FinalThesisAttacks$Government[FinalThesisAttacks$IS==0])
```

Fatalities
```{r}
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2016])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2017])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2018])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2019])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2020])

sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2016])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2017])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2018])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2019])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2020])

t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1], FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0])
t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2016], FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2016])
t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2017], FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2017])
t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2018], FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2018])
t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2019], FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2019])
t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2020], FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2020])
```

Suicide Attacks
```{r}
t.test(FinalThesisAttacks$Suicide[FinalThesisAttacks$IS==1], FinalThesisAttacks$Suicide[FinalThesisAttacks$IS==0])

table(FinalThesisAttacks$Suicide[FinalThesisAttacks$IS==1])
table(FinalThesisAttacks$Suicide[FinalThesisAttacks$IS==0])
```

Holidays
```{r}
t.test(FinalThesisAttacks$WesternHolidays[FinalThesisAttacks$IS==1], FinalThesisAttacks$WesternHolidays[FinalThesisAttacks$IS==0])

t.test(FinalThesisAttacks$IslamicHolidays[FinalThesisAttacks$IS==1], FinalThesisAttacks$IslamicHolidays[FinalThesisAttacks$IS==0])

t.test(FinalThesisAttacks$IraqSymbolic[FinalThesisAttacks$IS==1], FinalThesisAttacks$IraqSymbolic[FinalThesisAttacks$IS==0])

t.test(FinalThesisAttacks$ISSymbolic[FinalThesisAttacks$IS==1], FinalThesisAttacks$ISSymbolic[FinalThesisAttacks$IS==0])
```

Violence Against Women
```{r}
t.test(FinalThesisAttacks$Women[FinalThesisAttacks$IS==1], FinalThesisAttacks$Women[FinalThesisAttacks$IS==0])

table(FinalThesisAttacks$Women[FinalThesisAttacks$IS==1])
table(FinalThesisAttacks$Women[FinalThesisAttacks$IS==0])

sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==1 & FinalThesisAttacks$Women==1])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$IS==0 & FinalThesisAttacks$Women==1])
```

Violence Against IS
```{r}
t.test(FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==1], FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==0])

t.test(FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2016], FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2016])
t.test(FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2017], FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2017])
t.test(FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2018], FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2018])
t.test(FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2019], FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2019])
t.test(FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==1 & FinalThesisAttacks$year==2020], FinalThesisAttacks$AgainstIS[FinalThesisAttacks$IS==0 & FinalThesisAttacks$year==2020])

sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$AgainstIS==1 & FinalThesisAttacks$IS==1])
sum(FinalThesisAttacks$Fatalities[FinalThesisAttacks$AgainstIS==1 & FinalThesisAttacks$IS==0])
```

Suicide Attacks (Extra)
```{r}
t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$Suicide==1], FinalThesisAttacks$Fatalities[FinalThesisAttacks$Suicide==0])

t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$Suicide==1 & FinalThesisAttacks$IS==1], FinalThesisAttacks$Fatalities[FinalThesisAttacks$Suicide==0 & FinalThesisAttacks$IS==1])
t.test(FinalThesisAttacks$Fatalities[FinalThesisAttacks$Suicide==1 & FinalThesisAttacks$IS==0], FinalThesisAttacks$Fatalities[FinalThesisAttacks$Suicide==0 & FinalThesisAttacks$IS==0])
```


